uniform samplerCube refMap; //Reflection map
varying vec3 normal;        //Normal vector of this fragment
varying vec3 lightDir;      //Direction of the light
varying vec3 eyeVec;        //Direction of the line of sight
varying vec4 pos;           //Calculated position (Object space)
uniform vec3 camPos;       //Camera position

void main(void) {
    float z = gl_FragCoord.z / gl_FragCoord.w;
    vec4 Am = vec4(0.02, 0.72, 0.95, z/256); //Ambient material
    vec4 Dm = Am; //Diffuse material
    vec4 Sm = vec4(1.0, 1.0, 1.0, 1.0); //Specular material

    normal = normalize(normal);
    lightDir = normalize(lightDir);
    eyeVec = normalize(eyeVec);
    vec3 reflection = reflect(-lightDir, normal);
    vec3 eyeRef = reflect(-eyeVec, normal);
    float lambertTerm = dot(normal, lightDir);
    float specularIntensity = 0;

    if(lambertTerm > 0.0) {
        specularIntensity = pow(max(dot(reflection, eyeVec), 0.0), 100);
    }

    vec4 ambient = Am*gl_LightSource[0].ambient + Am*gl_LightModel.ambient;
    vec4 diffuse = Dm*gl_LightSource[0].diffuse*lambertTerm;
    vec4 specular = Sm*gl_LightSource[0].specular*specularIntensity;

    vec4 refColour = vec4(textureCube(refMap, eyeRef).rgb, 0.5);
    gl_FragColor = mix(ambient+diffuse+specular, refColour, 0.75);
    //gl_FragColor = ambient+diffuse+specular;


    //vec4 fogColour = vec4(0.5, 0.5, 0.5, 1.0);
    //float fogFactor = exp(-0.003*z);
    //fogFactor = clamp(fogFactor, 0.0, 1.0);
    //gl_FragColor = mix(fogColour, gl_FragColor, fogFactor);
}
